<!DOCTYPE html>
<html lang="en" class="js csstransforms3d">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="generator" content="Hugo 0.20.7" />
    <meta name="description" content="">


    <link rel="shortcut icon" href="http://shardingjdbc.io/document/legacy/2.x/cn/img/favicon.png" type="image/x-icon" />

    
    <title>概览</title>
    <link href="http://ovfotjrsi.bkt.clouddn.com/docs/css/nucleus.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="http://ovfotjrsi.bkt.clouddn.com/docs/css/theme.css" rel="stylesheet">
    <link href="http://ovfotjrsi.bkt.clouddn.com/docs/css/hugo-theme.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <style type="text/css">:root #header + #content > #left > #rlblock_left
    {display:none !important;}</style>
    <link rel="stylesheet" href="http://cdn.bootcss.com/highlight.js/9.8.0/styles/monokai-sublime.min.css">
<link rel="stylesheet" href="http://ovfotjrsi.bkt.clouddn.com/docs/css/style.css">
  </head>
  <body class="" data-url="/00-overview/">
    
    <nav id="sidebar">
  <div id="header-wrapper">
    <div id="header">
      <img src="http://ovfotjrsi.bkt.clouddn.com/docs/img/sharding-jdbc.png" />
    </div>
</div>
  <div class="highlightable">
    <ul class="topics">
      
        
        
          
          
            
          
        
          
          
            
          
        
          
          
            
          
        
          
          
            
          
        
        
        
          
        
          
        
          
        
          
        
      
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item active parent" data-nav-id="/00-overview/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/cn/00-overview/">
          <span>
            
              <b>0. </b>
            
             概览
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/00-overview/intro/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/00-overview/intro/">
                <span>简介     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/00-overview/news/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/00-overview/news/">
                <span>新闻     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/00-overview/contribution/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/00-overview/contribution/">
                <span>贡献代码     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  " data-nav-id="/01-start/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/">
          <span>
            
              <b>1. </b>
            
             起航
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/01-start/quick-start/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/quick-start/">
                <span>快速入门     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/code-demo/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/code-demo/">
                <span>使用示例     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/faq/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/faq/">
                <span>FAQ     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/features/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/features/">
                <span>详细功能列表     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/limitations/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/limitations/">
                <span>使用限制     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/sql-supported/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/sql-supported/">
                <span>SQL支持详细列表     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/01-start/stress-test/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/01-start/stress-test/">
                <span>性能测试报告     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  " data-nav-id="/02-guide/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/">
          <span>
            
              <b>2. </b>
            
             使用指南
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/02-guide/concepts/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/concepts/">
                <span>核心概念     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/sharding/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/sharding/">
                <span>分库分表     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/master-slave/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/master-slave/">
                <span>读写分离     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/config_domain/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/config_domain/">
                <span>配置域模型     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/configuration/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/configuration/">
                <span>配置手册     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/orchestration/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/orchestration/">
                <span>编排治理     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/hint-sharding-value/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/hint-sharding-value/">
                <span>强制路由     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/key-generator/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/key-generator/">
                <span>分布式主键     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/transaction/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/transaction/">
                <span>事务支持     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/subquery/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/subquery/">
                <span>分页及子查询     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/test-framework/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/test-framework/">
                <span>测试引擎     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/apm/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/apm/">
                <span>应用性能监控     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/02-guide/sharding-jdbc-server/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/02-guide/sharding-jdbc-server/">
                <span>Sharding-JDBC-Server     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
      

      
      
      
        
          
          
            
          
        
      
      
      

      <li class="dd-item  " data-nav-id="/03-design/">
        <a href="http://shardingjdbc.io/document/legacy/2.x/cn/03-design/">
          <span>
            
              <b>3. </b>
            
             设计规划
            
           </span>
        </a>
        
        <ul>
          
            <li class="dd-item " data-nav-id="/03-design/architecture/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/03-design/architecture/">
                <span>架构设计     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/03-design/module/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/03-design/module/">
                <span>模块说明     </i></span>
              </a>
            </li>
          
            <li class="dd-item " data-nav-id="/03-design/roadmap/">
              <a href="http://shardingjdbc.io/document/legacy/2.x/cn/03-design/roadmap/">
                <span>未来线路规划     </i></span>
              </a>
            </li>
          
        </ul>
        
      </li>
      
      
    </ul>
    <hr>
     
  </div>
</nav>

        <section id="body">
        <div id="overlay"></div>

        <div class="padding highlightable">

            <div id="top-bar">
              
              <div id="breadcrumbs" itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb">
                  <span id="sidebar-toggle-span">
                      <a href="#" id="sidebar-toggle" data-sidebar-toggle="">
                        <i class="fa fa-bars"></i>
                      </a>
                  </span>
                
                
                  
                  
                  
                    
                    
                  
                
                <span itemprop="title"> 概览</span>
              </div>
              

            </div>
            
              <div id="chapter">
            
              <div id="body-inner">
                



<h1 id="概述">概述</h1>

<p><a href="https://github.com/shardingjdbc/sharding-jdbc/releases"><img src="https://img.shields.io/github/release/shardingjdbc/sharding-jdbc.svg?style=social&amp;label=Release" alt="GitHub release" /></a>&nbsp;
<a href="https://github.com/shardingjdbc/sharding-jdbc/stargazers"><img src="https://img.shields.io/github/stars/shardingjdbc/sharding-jdbc.svg?style=social&amp;label=Star" alt="GitHub stars" /></a>&nbsp;
<a href="https://github.com/shardingjdbc/sharding-jdbc/fork"><img src="https://img.shields.io/github/forks/shardingjdbc/sharding-jdbc.svg?style=social&amp;label=Fork" alt="GitHub forks" /></a>&nbsp;
<a href="https://github.com/shardingjdbc/sharding-jdbc/watchers"><img src="https://img.shields.io/github/watchers/shardingjdbc/sharding-jdbc.svg?style=social&amp;label=Watch" alt="GitHub watchers" /></a></p>

<p>Sharding-JDBC是一个开源的分布式数据库中间件解决方案。它在Java的JDBC层以对业务应用零侵入的方式额外提供数据分片，读写分离，柔性事务和分布式治理能力。并在其基础上提供封装了MySQL协议的服务端版本，用于完成对异构语言的支持。</p>

<p>基于JDBC的客户端版本定位为轻量级Java框架，使用客户端直连数据库，以jar包形式提供服务，无需额外部署和依赖，可理解为增强版的JDBC驱动，完全兼容JDBC和各种ORM框架。</p>

<p>封装了MySQL协议的服务端版本定位为透明化的MySQL代理端，可以使用任何兼容MySQL协议的访问客户端(如：MySQL Command Client, MySQL Workbench等)操作数据，对DBA更加友好。</p>

<p><a href="https://www.apache.org/licenses/LICENSE-2.0.html"><img src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg" alt="License" /></a></p>

<p><a href="https://maven-badges.herokuapp.com/maven-central/io.shardingjdbc/sharding-jdbc"><img src="https://maven-badges.herokuapp.com/maven-central/io.shardingjdbc/sharding-jdbc/badge.svg" alt="Maven Status" /></a>
<a href="https://github.com/shardingjdbc/sharding-jdbc/releases"><img src="https://img.shields.io/github/release/shardingjdbc/sharding-jdbc.svg" alt="GitHub release" /></a>

<p><a href="https://travis-ci.org/shardingjdbc/sharding-jdbc"><img src="https://secure.travis-ci.org/shardingjdbc/sharding-jdbc.png?branch=master" alt="Build Status" /></a>
<a href="https://codecov.io/github/shardingjdbc/sharding-jdbc?branch=master"><img src="https://codecov.io/github/shardingjdbc/sharding-jdbc/coverage.svg?branch=master" alt="Coverage Status" /></a>
<a href="https://gitter.im/Sharding-JDBC/shardingjdbc?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge"><img src="https://badges.gitter.im/Sharding-JDBC/shardingjdbc.svg" alt="Gitter" /></a>
<a href="http://opentracing.io"><img src="https://img.shields.io/badge/OpenTracing--1.0-enabled-blue.svg" alt="OpenTracing-1.0 Badge" /></a>
<a href="https://github.com/OpenSkywalking/skywalking"><img src="https://img.shields.io/badge/Skywalking%20Tracing-enable-brightgreen.svg" alt="Skywalking Tracing" /></a></p>

<h1 id="功能列表">功能列表</h1>

<h2 id="1-数据分片">1. 数据分片</h2>

<ul>
<li>支持分库 + 分表</li>
<li>支持聚合，分组，排序，分页，关联查询等复杂查询语句</li>
<li>支持常见的DML，DDL，TCL以及数据库管理语句</li>
<li>支持=，BETWEEN，IN的分片操作符</li>
<li>自定义的灵活分片策略，支持多分片键共用，支持inline表达式</li>
<li>基于Hint的强制路由</li>
<li>支持分布式主键</li>
</ul>

<h2 id="2-读写分离">2. 读写分离</h2>

<ul>
<li>支持一主多从的读写分离</li>
<li>支持同一线程内的数据一致性</li>
<li>支持分库分表与读写分离共同使用</li>
<li>支持基于Hint的强制主库路由</li>
</ul>

<h2 id="3-柔性事务">3. 柔性事务</h2>

<ul>
<li>最大努力送达型事务</li>
<li>TCC型事务(TBD)</li>
</ul>

<h2 id="4-分布式治理">4. 分布式治理</h2>

<ul>
<li>支持配置中心，可动态修改配置</li>
<li>支持客户端熔断和失效转移</li>
<li>支持Open Tracing协议</li>
</ul>

<h1 id="部署架构">部署架构</h1>

<h2 id="sharding-jdbc-driver">Sharding-JDBC-Driver</h2>

<p>通过客户端分片的方式由应用程序直连数据库，减少二次转发成本，性能最高，适合线上程序使用。</p>

<ul>
<li>可适用于任何基于Java的ORM框架，如：JPA, Hibernate, Mybatis, Spring JDBC Template或直接使用JDBC。</li>
<li>可基于任何第三方的数据库连接池，如：DBCP, C3P0, BoneCP, Druid等。</li>
<li>可支持任意实现JDBC规范的数据库。目前支持MySQL，Oracle，SQLServer和PostgreSQL。</li>
</ul>

<p><img src="http://ovfotjrsi.bkt.clouddn.com/jdbc_brief_cn.png" alt="Sharding-JDBC-Driver Architecture" /></p>

<h2 id="sharding-jdbc-server">Sharding-JDBC-Server</h2>

<p>通过代理服务器连接数据库(目前仅支持MySQL)，适合其他开发语言或MySQL客户端操作数据。</p>

<ul>
<li>向应用程序完全透明，可直接当做MySQL使用。</li>
<li>可适用于任何兼容MySQL协议的客户端。</li>
</ul>

<p><img src="http://ovfotjrsi.bkt.clouddn.com/proxy_brief_cn.png" alt="Sharding-JDBC-Server Architecture" /></p>

<h2 id="sharding-jdbc-sidecar-tbd">Sharding-JDBC-Sidecar(TBD)</h2>

<p>通过sidecar分片的方式，由IPC代替RPC，自动代理SQL分片，适合与Kubernetes或Mesos配合使用。</p>

<p><img src="http://ovfotjrsi.bkt.clouddn.com/sidecar_brief_v2_cn.png" alt="Sharding-JDBC-Sidecar Architecture" /></p>

<h1 id="快速入门">快速入门</h1>

<h2 id="sharding-jdbc-driver-1">Sharding-JDBC-Driver</h2>

<h3 id="引入maven依赖">引入maven依赖</h3>

<pre><code class="language-xml">&lt;!-- 引入sharding-jdbc核心模块 --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.shardingjdbc&lt;/groupId&gt;
    &lt;artifactId&gt;sharding-jdbc-core&lt;/artifactId&gt;
    &lt;version&gt;${latest.release.version}&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<h3 id="规则配置">规则配置</h3>

<p>Sharding-JDBC可以通过<code>Java</code>，<code>YAML</code>，<code>Spring命名空间</code>和<code>Spring Boot Starter</code>四种方式配置，开发者可根据场景选择适合的配置方式。</p>

<h3 id="创建datasource">创建DataSource</h3>

<p>通过ShardingDataSourceFactory工厂和规则配置对象获取ShardingDataSource，ShardingDataSource实现自JDBC的标准接口DataSource。然后即可通过DataSource选择使用原生JDBC开发，或者使用JPA, MyBatis等ORM工具。</p>

<pre><code class="language-java">DataSource dataSource = ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig);
</code></pre>

<h2 id="sharding-jdbc-server-1">Sharding-JDBC-Server</h2>

<h3 id="规则配置-1">规则配置</h3>

<p>编辑<code>${sharding-jdbc-server}\conf\sharding-config.yaml</code>。配置规则同Sharding-JDBC-Driver的<code>YAML</code>格式。</p>

<h3 id="启动服务">启动服务</h3>

<pre><code class="language-shell">${sharding-jdbc-server}\bin\start.sh ${port}
</code></pre>


      
      
        </div> 
      
      </div>
    </div>

    

    <div id="navigation">
        
        <a class="nav nav-prev" href="http://shardingjdbc.io/document/legacy/2.x/cn/03-design/roadmap/"> <i class="fa fa-chevron-left"></i></a>
        <a class="nav nav-next" href="http://shardingjdbc.io/document/legacy/2.x/cn/00-overview/intro/" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
    </div>

    </section>
    <div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
      <div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
    </div>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/clipboard.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/perfect-scrollbar.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/perfect-scrollbar.jquery.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/jquery.sticky-kit.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/featherlight.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/html5shiv-printshiv.min.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/learn.js"></script>
    <script src="http://ovfotjrsi.bkt.clouddn.com/docs/js/hugo-learn.js"></script>
    <script src="http://cdn.bootcss.com/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

  </body>
</html>

